from playwright.sync_api import sync_playwright

from src.utils.BrowserUtil import BrowserUtil


def main():
    # p = sync_playwright().start()
    # browser = p.chromium.launch(headless=False)
    # page = browser.new_page()
    # page.goto("https://www.baidu.com")
    # print(page.title())
    # page.locator("#kw").fill("Playwright")
    # page.locator("#su").click()
    # page.wait_for_timeout(3000)
    # lcs = page.locator('//a[@data-showurl-highlight="true"]').all()
    # print(lcs)
    # for lc in lcs:
    #     print(lc.inner_text())
    #
    # browser.close()
    # p.stop()
    util = BrowserUtil()
    util.open_browser(headless=False)
    page = util.open_page("https://www.baidu.com")
    print(page.title())
    page.locator("#kw").fill("Playwright")
    page.locator("#su").click()
    page.wait_for_timeout(3000)
    lcs = page.locator('//a[@data-showurl-highlight="true"]').all()
    print(lcs)
    for lc in lcs:
        print(lc.inner_text())

    util.close_browser()

if __name__ == "__main__":
    main()